﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using FightTheDragon.GameObjects;

namespace FightTheDragon.Managers
{
    class ObjectManager
    {
        private static ObjectManager m_Instance = new ObjectManager();
        private List<BaseObject> m_Objects;
        public List<BaseObject> Objects
        {
            get { return m_Objects; }
            set { m_Objects = value; }
        }

        public static ObjectManager Instance
        {
            get { return m_Instance; }
        }

        private ObjectManager()
        {
            m_Objects = new List<BaseObject>();

        }

        public void Shutdown()
        {
            m_Objects.Clear();
        }
        public void Render()
        {
            foreach (BaseObject B in m_Objects)
                B.Render();
        }
        public void Update(float gameTime)
        {
            foreach (BaseObject B in m_Objects)
                B.Update(gameTime);
        }
        public void CheckCollision()
        {
            foreach (BaseObject A in m_Objects)
            {
                foreach (BaseObject B in m_Objects)
                {
                    if (A.NObjectType != B.NObjectType)
                    {
                        //Add HealthReduction after Damage is put in
                        A.CheckCollision(B);
                    }
                }

            }
        }
        public void Run(float gameTime)
        {
            Render();

            Update(gameTime);

            CheckCollision();
        }
        public void Remove(BaseObject B)
        {
            m_Objects.Remove(B);
            
        }
        public void RemoveAll()
        {
            m_Objects.Clear();
        }
        public void Add(BaseObject B)
        {
            m_Objects.Add(B);
        }
    }
}
